package com.itheima.controller;

import com.itheima.anno.OperateLog;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

//    //查询所有员工的信息
//    @GetMapping("/emps")
//    public Result list(){
//        List<Emp> emp = empService.findAll();
//        return Result.success(emp);
//    }
    //分页查询
    @GetMapping("/emps")
    public Result findAll(EmpQueryParam e){
        PageResult pageBean = empService.findAll(e);
        return Result.success(pageBean);
    }

    @OperateLog
    //新增员工
    @PostMapping("/emps")
    public Result save(@RequestBody Emp emp){
        log.info("新增员工信息：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @OperateLog
    //删除员工
    @DeleteMapping("/emps")
    public Result delete(Integer[] ids){
        empService.deleteById(ids);
        return Result.success();
    }

    //根据id查询员工信息
    @GetMapping("/emps/{id}")
    public Result findById(@PathVariable("id") Integer id){
        Emp e = empService.findById(id);
        return Result.success(e);
    }

    @OperateLog
    //修改员工信息
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }

    //查询所有员工
    @GetMapping("/emps/list")
    public Result list(){
        List<Emp> list = empService.list();
        return Result.success(list);
    }



}
